<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>确认订单</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css"/>
    <style>
        body {
            background: #f3f3f3;
            font-size: 14px;
        }

        header {
            width: 100%;
            background: #fff;
            position: relative;
            z-index: 9;
        }

        .content {
            display: inline-block;
        }

        .contents {
            margin-left: 25px;
            margin-right: 15px;
            text-align: left;
        }

        .contents > span {
            display: block;
        }

        .address {
            margin-top: 4px;
        }

        .addressTop.aui-tab-nav li {
            line-height: inherit;
            height: auto;
            position: relative;
            padding: 15px;
            width: 100%;
            color: #fff;
        }

        .aui-tab-nav {
            height: inherit;
            display: block;
            background: #4f6ea6;
        }

        .haderTitle li > span {
            float: left;
            display: block;
        }

        .detail {
            overflow: hidden;
            padding: 5px 15px;
        }

        .good-pirce {
            color: #ff0005;
            font-weight: bold;
        }

        .total {
            margin-top: 10px;
        }

        .haderTitle li > span {
            float: left;
            display: block;
        }

        .contain .aui-tab-nav li {
            line-height: inherit;
            height: auto;
            position: relative;
            padding: 15px;
            width: 100%;
        }

        .contain .aui-tab-nav {
            height: inherit;
            display: block;
        }

        .contents {
            margin-left: 25px;
            margin-right: 15px;
            text-align: left;
        }

        .content {
            display: inline-block;
        }

        .contents > span {
            display: block;
        }

        .time {
            display: block;
        }

        .address {
            margin-top: 8px;
        }

        .good {
            background: #fff;
            margin-bottom: 15px;
        }

        .good-pirce {
            color: #ff0005;
            font-weight: bold;
        }

        .company-name {
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            background: #fff;
            padding-left: 15px;
            position: relative;
        }

        .good_bottom ul li {
            overflow: hidden;
            margin-bottom: 5px;
        }

        .good_bottom ul li span {
            display: block;
        }

        .good-info .aui-list-view {
            margin: 0;
        }

        .menuRgiht {
            float: right;
            margin-right: 20px;
        }

        .good_bottom {
            background: #fff;
        }

        .aui-iconfont {
            margin-right: 5px;
        }

        .total .good-pirce {
            font-size: 18px;
        }

        input[type="text"] {
            margin: 0;
        }

        .pickerToTop .aui-iconfont {
            position: absolute;
            left: 10px;
            top: 10px;
            font-size: 20px;
            color: #000;
            z-index: 9;
        }

        .good_bottom .aui-list-view:after {
            border: 0;
        }

        span.xiaoji {
            position: relative;
            display: block;
            padding: 0 8px;
        }

        span.xiaoji:nth-of-type(2):before {
            position: absolute;
            content: "";
            width: 1px;
            background: #b6b6b6;
            top: 2px;
            right: 0;
            bottom: 2px;
        }

        .good-info {
            margin-bottom: 15px;
        }

        .pickerToTop ul li:not(:first-of-type) {
            font-size: 14px;
        }

        .payList li {
            position: relative;

        }

        .payList li img {
            width: 25px;
            vertical-align: middle;
            margin-right: 5px;
        }

        .locationMove {
            -webkit-animation: locationMove-animation 1.5s infinite cubic-bezier(0.52, 1.64, 0.37, 0.66);
            -o-animation: locationMove-animation 1.5s infinite cubic-bezier(0.52, 1.64, 0.37, 0.66);
            animation: locationMove-animation 1.5s infinite cubic-bezier(0.52, 1.64, 0.37, 0.66);
        }

        @keyframes locationMove-animation {
            0% {
                opacity: 0;
            }
            50% {
                opacity: 0;
                -webkit-transform: translateY(-100%);
                transform: translateY(-100%);
            }
            51%,
            100% {
                opacity: 1;
            }
        }

        @-webkit-keyframes locationMove-animation {
            0% {
                opacity: 0;
            }
            50% {
                opacity: 0;
                -webkit-transform: translateY(-100%);
                transform: translateY(-100%);
            }
            51%,
            100% {
                opacity: 1;
            }
        }

        .aui-checkbox:checked:before, .aui-checkbox.aui-checked:before {
            top: -5px;
            left: 1px;
        }
    </style>
</head>

<body>
<div class="payContain dispalyNone-unImportant">
    <div class="contain">

        <div class="font-weight-700 aui-text-danger line-height-34 aui-text-center aui-border-b noAddress" tapmode
             onclick="chooseAddress('orderConfirm')">
            <div class="positionARelative">
                <i class="aui-iconfont aui-icon-locationfill locationMove positionAbsolute "
                   style="left: 50%;margin-left: -90px;"></i>
                <div>请先设置收获地址>>
                </div>
            </div>
        </div>
        <ul class="aui-tab-nav aui-border-t haderTitle addressTop hasAddress">
            <li class="aui-arrow-right" tapmode onclick="chooseAddress('orderConfirm')">
                <span class="aui-iconfont aui-icon-location icon"></span>
                <div class="contents">
                    <span class="aui-pull-left">收货人：<em class="address_name">---</em></span>
                    <span class="phone aui-pull-right"><em class="address_phone">---</em></span>
                    <div class="content address aui-ellipsis-1">收获地址：<em class="address_address">---</em></div>
                </div>
            </li>
        </ul>
        <div class="aui-input-row aui-padded-0-10 payMethod bg-white">
            <label class="aui-input-addon aui-text-danger font-weight-700">支付方式</label>
            <div class="aui-pull-right">
                <input class="aui-radio noBefore" type="radio" value="Wxpay" name="radioPay" checked>
                <div class="aui-radio-name">微信支付</div>
                <!--<input class="aui-radio  noBefore" type="radio" value="Alipay" name="radioPay">-->
                <!--<div class="aui-radio-name">支付宝支付</div>-->
            </div>
        </div>
        <div class=" aui-border-b aui-flex-col aui-padded-10 bg-white">
            <div class="aui-flex-row aui-flex-middle aui-flex-item-6">货品清单</div>
            <div class="aui-flex-item-6 aui-hide">
                <div class="aui-btn aui-btn-danger aui-bg-danger  aui-padded-5-10 aui-flex-right aui-flex-row aui-pull-right ">
                    修改
                </div>
            </div>
        </div>

        <div class="goodList" id="goodList-content">
        </div>
    </div>
</div>

<script id="goodList-template" type="text/x-dot-template">
    <div class="good">
        <div class="good-info">

            <ul class="aui-list-view">
                <li class="aui-list-view-cell aui-img aui-counter-list">
                    <div class="overhidden">
                        <img class="aui-img-object aui-pull-left" src="{{=it.original_img}}">
                        <div class="aui-img-body">
                            <span class="good-name aui-ellipsis-2">{{=it.goods_name}}</span>
                            <div class="good-info-lists">
                                <div class=" aui-pull-left good-pirce">￥{{=it.show_price}}</div>
                                <div class=" aui-pull-right">x<span class="good-count" id="count{{=it.goods_id}}">*</span></div>
                            </div>
                        </div>
                    </div>
                    {{? it.vmoney_user>0}}
                    <div class="  aui-pull-right aui-margin-0 aui-pull-left">
                        <input type="hidden" value="{{=it.vmoney_user}}" id="song-jifen-value-{{=it.goods_id}}">
                        <em class="aui-text-default">订单完成赠送</em>
                        <span class=" shangjing-color2 font-szie-18  "><em class="song-jifen-{{=it.goods_id}}">{{=it.vmoney_user}}</em>积分</span>
                    </div>
                    {{??}}
                    <div class="  aui-pull-right aui-margin-0 aui-pull-right">

                        <em>可用</em>
                        <input type="hidden" value="{{=it.vmoney_unbackable}}" id="di-jifen-value-{{=it.goods_id}}">
                        <span class=" shangjing-color2 font-szie-18  "><em
                                class="di-jifen-{{=it.goods_id}}">{{=it.vmoney_unbackable}}</em>积分</span>
                        <span>抵<em class="di-jifen-{{=it.goods_id}}">{{=it.vmoney_unbackable}}</em>元</span>
                    </div>
                    {{}}}
                </li>
            </ul>
            <div class="good_bottom aui-hide">
                <ul class="aui-list-view">
                    <li class="aui-list-view-cell">
                        <span class="aui-pull-right xiaoji">小计：<em class="good-pirce0">￥<em
                                class="goodTotalMoney">82.20</em></em></span>
                        <span class="aui-pull-right xiaoji"><em class="xiaojiTotalCount">--</em>件</span>
                    </li>
                </ul>
            </div>
        </div>
    </div>


</script>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript">
    var goodOrderInfo = "", goodId = "", orderType = "", count, aijiangliOrderId = "";
    var addressId = "", hasSubmit_OrderId = "";
    var vmoney="";
    var goodTotalMoney=0;
    var index=0;//记录有没显示全部商品了
    apiready = function () {
        //防止重复提交同个订单
        $api.setStorage("hasSubmit_OrderId", "");
        showLoading()
        getUserInfo();
        api.parseTapmode();
        goodOrderInfo = JSON.parse(api.pageParam.goodOrderInfo);
        for (var i=0;i<goodOrderInfo.length;i++){
            getGoodInfo(goodOrderInfo[i]["goods_id"],goodOrderInfo[i]["goods_number"])
        }



        orderType = api.pageParam.orderType;
        count = api.pageParam.count;
        goodId = api.pageParam.goodId;

        var header = $api.dom('header');
        var footer = $api.dom('footer');
        $api.fixIos7Bar(header);
        //延迟加载getUserInfo数据
        setTimeout(function () {
//            getGoodInfo()
        }, 1000)
        //获取新的收获地址
        api.addEventListener({
            name: "updateConfirmAddress",
        }, function (ret, err) {
            if (ret && ret.value) {
//                getUserInfo();
//                getGoodInfo()
                $(".address_name").text(ret.value.address_name);
                $(".address_phone").text(ret.value.address_phone);
                $(".address_address").text(ret.value.address_address);
                addressId = ret.value.address_id;
                $(".hasAddress").show();
                $(".noAddress").hide();
            }
        })
    }

    //获取商品详情
    function getGoodInfo(good_id,good_count) {
        var url = "goods/info";
        var data = {};
        data["goods_id"] = good_id;
        getStorageAll();
        ajaxRequest(url, 'get', data, function (ret, err) {
//            hideLoading();
            var content = $api.byId('goodList-content');
            var tpl = $api.byId('goodList-template').text;
            var tempFn = doT.template(tpl);

            $api.append(content, tempFn(ret.data));
            vmoney=ret.data.vmoney_user>0?ret.data.vmoney_user:ret.data.vmoney_unbackable;
//            if (orderType == "singleGood") {
//                //商品详情页进来的
//                $api.html(content, tempFn(ret.data));
//                $(".good-count").text(count);
//                $(".xiaojiTotalCount").text(count);
//                $(".goodTotalMoney").text(count * ret.data.shop_price);
//                api.sendEvent({
//                    name: "showTotalMoney",
//                    extra: {
//                        totalMoney: count * ret.data.shop_price
//                    }
//                })
//            } else {
//                $api.append(content, tempFn(ret.data));
//            }
            //显示数量
            $("#count"+good_id).text(good_count);
            //显示抵积分
//            alert($("#di-jifen-value-"+good_id).val())
//            alert(ret.data.vmoney_user+"ddddddd"+good_id)
            $(".di-jifen-"+good_id).text(good_count*$("#di-jifen-value-"+good_id).val());
            //显示送
            $(".song-jifen-"+good_id).text(good_count*$("#song-jifen-value-"+good_id).val());

            goodTotalMoney=goodTotalMoney+good_count*ret.data.show_price;






            //积分处理
            handlePrice();

            index++;
            if(index==goodOrderInfo.length){
                //收获地址处理
                if (address_info) {
                    $(".hasAddress").show();
                    $(".noAddress").hide();
                    $(".address_name").text(address_info.consignee)
                    $(".address_phone").text(address_info.mobile)
                    $(".address_address").text(address_info.address)
                } else {
                    $(".hasAddress").hide();
                    $(".noAddress").show();
                }
                api.sendEvent({
                    name: "showTotalMoney",
                    extra: {
                        totalMoney: goodTotalMoney
                    }
                })
                $(".payContain").show()
            }

//            $api.html(content, tempFn(ret.data));
        });
    }
    function checkCardFn(obj) {
        $(obj).parent().find("li").removeClass("payActive");
        $(obj).addClass("payActive");
        $(".payMethod").text($(obj).text());
        showCheckCardBack();
    }
    function surePay() {
        showLoading();
        var payMethod = "Wxpay";
        $(".payMethod").find("input:radio[name='radioPay']").each(function () {
            if ($(this).prop("checked")) {
                payMethod = $(this).val();
            }
        })
        if (payMethod == "Wxpay") {
            var goodInfoArray = [];
            var goodInfo = {};

//            goodInfo['goods_id'] = goodId;
//            goodInfo['goods_number'] = count;
            goodInfoArray.push(goodInfo)

            hasSubmit_OrderId = $api.getStorage("hasSubmit_OrderId");
            if (hasSubmit_OrderId != "") {
                payOfOrderId();
            } else {
                getOrderId(goodOrderInfo)
            }

        }
//        else if (payMethod == "Alipay") {
//            aliPay("dd", "ddd", "500", "18641")
//        }
    }
    //获取平台的的为order_sn
    function getOrderId(goodInfo) {
        var url = "order/add";
        ajaxRequest(url, 'post', {goods: goodInfo, address_id: addressId}, function (ret, err) {

            //返回尚景的订单号
            aijiangliOrderId = ret.data.order_id;
            //防止用户取消付款后提交重复订单
            $api.setStorage("hasSubmit_OrderId", aijiangliOrderId)
            payOfOrderId();
            //有平台的orderid去获取获取微信支付的orderid，和支付的一些信息


        });
    }
    function payOfOrderId() {
        var getPayOrderIdUrl = "order/payparam";
        var dataOrder = {};
        dataOrder["order_id"] = $api.getStorage("hasSubmit_OrderId");
        ajaxRequest(getPayOrderIdUrl, 'get', dataOrder, function (ret, err) {
            var appid = ret.data.appid;
            var noncestr = ret.data.noncestr;
            var package = ret.data.package;
            var partnerid = ret.data.partnerid;
            var prepayid = ret.data.prepayid;
            var sign = ret.data.sign;
            var timestamp = ret.data.timestamp;
            wxpay(appid, noncestr, package, partnerid, prepayid, sign, timestamp, "");
            //订单充值未空
            aijiangliOrderId = "";
        })
    }
    //去设置地址
    function chooseAddress(type) {
        api.openWin({
            name: "goTOSetAddress",
            url: "addressList_win.html",
            pageParam: {
                type: type,
            }
        })
    }
    //单击金豆多选款
    function clickBeansCheckbox(obj) {
        var $MyBeansParent = $(obj).closest(".beansControl");
        var myBeans = $MyBeansParent.find(".myBeans").eq(0).text();
        var goodPrice = $MyBeansParent.next().find(".singlePrice").text();

        if ($(obj).prop("checked")) {
            $MyBeansParent.next().find(".payMount").text(goodPrice - myBeans)
        } else {
            $MyBeansParent.next().find(".payMount").text(goodPrice)
        }
    }
    //处理价格，积分的
    function handlePrice() {
        //一件单品的积分

        var count = $(".good-count").text();
        $(".vmoney").text(vmoney * count);
//        $(".integralMoney").text(goodIntegral * count)
    }
</script>

</html>
